FROM php:7.1.3-fpm
#ADD sources.list /etc/apt/sources.list

ENV PHALCON_VERSION=3.3.2
ENV REDIS_VERSION=4.0.0
ENV SWOOLE_VERSION=4.2.0

# mysql pdo_mysql gd curl swoole memcached redis zip
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
    echo "Asia/Shanghai" > /etc/timezone
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
    echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
    echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

RUN apt-get update && apt-get install -y \
    htop \
    inetutils-ping \
    vim \
    git \
    wget \
    zlib1g-dev \
    libfreetype6-dev \
    libmemcached-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libpng12-dev \
    libz-dev \
    # openssl 依赖
    libcurl4-openssl-dev \
    pkg-config \
    libssl-dev \
    # 官方 PHP 镜像内置命令，安装 PHP 依赖
    && docker-php-ext-configure gd \
        --with-gd \
        --with-freetype-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install \
        zip \
        gd \
        pdo_mysql \
        mysqli \
        mbstring \
        bcmath \
    # 用完包管理器后安排打扫卫生可以显著的减少镜像大小
    && apt-get clean \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


RUN pecl install mongodb 
    #docker-php-ext-enable mongodb
    #echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/mongodb.ini

RUN pecl install xdebug  && \
    docker-php-ext-enable xdebug   

# Compile Phalcon
RUN set -xe && \
    curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz && \
    tar xzf v${PHALCON_VERSION}.tar.gz && cd cphalcon-${PHALCON_VERSION}/build && ./install && \
    echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini && \
    cd ../.. && rm -rf v${PHALCON_VERSION}.tar.gz cphalcon-${PHALCON_VERSION}
    # Insall Phalcon Devtools, see https://github.com/phalcon/phalcon-devtools/
    #curl -LO https://github.com/phalcon/phalcon-devtools/archive/v${PHALCON_VERSION}.tar.gz && \
    #tar xzf v${PHALCON_VERSION}.tar.gz && \
    #mv phalcon-devtools-${PHALCON_VERSION} /usr/local/phalcon-devtools && \
    #ln -s /usr/local/phalcon-devtools/phalcon.php /usr/local/bin/phalcon 

#RUN set -xe && \
#    git clone https://github.com/phalcon/phalcon-devtools.git && \
#    cd phalcon-devtools  && \
#    ln -s $(pwd)/phalcon.php /usr/bin/phalcon  && \
#    chmod ugo+x /usr/bin/phalcon


# redis
RUN set -xe && \
    curl -LO http://pecl.php.net/get/redis-${REDIS_VERSION}.tgz && \
    pecl install redis-${REDIS_VERSION}.tgz && \
    #echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini && \
    docker-php-ext-enable redis && \
    rm -rf redis-${REDIS_VERSION}.tar.gz


# swoole
RUN pecl install swoole  && \
    docker-php-ext-enable swoole 

RUN echo "alias ll='ls $LS_OPTIONS -l'" >> /root/.bashrc

#Composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer
        
EXPOSE 9000
